// 	ID : pallab81
// 	PROG : 11456
// 	LANG : C++
// 	2011-08-27-11.39.36 Saturday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define mmk( x, y, z ) make_pair( x, make_pair( y , z ) )

inline void wait( double seconds ){
    double endtime = clock() + ( seconds*CLOCKS_PER_SEC );
    while( clock() < endtime ){;}
}
int n;
vector< int > w;
inline void Read(){
    CI(n);
    w.assign(n,0);
    int x;
    fo(i,n){
        CI(x);
        w[n-(i+1)]=x;
    }
}


inline void Proc(){
    vector<int> lis(n,0);
    for(int i=0;i<n;++i){
        int longest = 0;
        for(int j=0; j<i; ++j){
            if( w[i] > w[j] && (lis[j] > longest) ){
                longest = lis[j];
            }
        }
        lis[i] = longest+1;
    }
    vector<int> lds(n,0);
    for(int i=0;i<n;++i){
        int longest = 0;
        for(int j=0;j<i;++j){
            if( w[i] < w[j] && (lds[j] > longest) ){
                longest = lds[j];
            }
        }
        lds[i] = longest+1;
    }
    int mx = 0;
    fo(i,n){
        //printf("%d = %d : %d\n",i+1,lis[i],lds[i]);
        mx = max(mx, lis[i]+lds[i]-1);
    }
    printf("%d\n",mx);
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","rt",stdin);
    #endif

    int cases=1;
    for( CI(cases) ; cases ; --cases ){
        Read();
        Proc();
    }
return 0;
}
